home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / commands / termcap.c < prev    next >
C/C++ Source or Header  |  1990-07-20  |  4KB  |  162 lines

  1. /* termcap - print termcap settings    Author: Terrence Holm */
  2.  
  3. #include <stdio.h>
  4.  
  5. #define  TC_BUFFER  1024    /* Size of termcap(3) buffer    */
  6.  
  7. char *getenv();
  8. char *tgetstr();
  9.  
  10. /****************************************************************/
  11. /*                                */
  12. /*    termcap  [ type ]                        */
  13. /*                                */
  14. /*    Prints out all of the termcap capabilities as described    */
  15. /*    in termcap(4). If "type" is not supplied then $TERM is    */
  16. /*    used.                            */
  17. /*                                */
  18. /****************************************************************/
  19.  
  20.  
  21. main( argc, argv )
  22.   int   argc;
  23.   char *argv[];
  24.  
  25.   {
  26.   char *term;
  27.   char  buffer[ TC_BUFFER ];
  28.  
  29.  
  30.   /*  Check for an argument  */
  31.  
  32.   if ( argc > 2 )
  33.     Error( "Usage:  %s  [ type ]\n", argv[0] );
  34.  
  35.   if ( argc == 2 )
  36.     term = argv[1];
  37.   else
  38.     term = getenv( "TERM" );
  39.  
  40.   if ( term == NULL )
  41.     Error( "termcap:  $TERM is not defined\n", "" );
  42.  
  43.  
  44.   /*  Read in the termcap entry  */
  45.  
  46.   if ( tgetent( buffer, term ) != 1 )
  47.     Error( "termcap:  No termcap entry for %s\n", term );
  48.  
  49.  
  50.   /*  Print out the entry's contents  */
  51.  
  52.   printf( "TERM = %s\n\n", term );
  53.  
  54.   if ( tgetflag( "am" ) == 1 )
  55.     printf( "End of line wraps to next line   (am)\n" );
  56.  
  57.   if ( tgetflag( "bs" ) == 1 )
  58.     printf( "Ctrl/H performs a backspace      (bs)\n" );
  59.  
  60.   printf( "Number of columns                (co) = %d\n", tgetnum( "co" ) );
  61.   printf( "Number of lines                  (li) = %d\n", tgetnum( "li" ) );
  62.  
  63.   Print( "Clear to end of line",       "ce" );
  64.   Print( "Clear to end of screen",       "cd" );
  65.   Print( "Clear the whole screen",      "cl" );
  66.  
  67.   Print( "Start \"stand out\" mode",      "so" );
  68.   Print( "End \"stand out\" mode",      "se" );
  69.   Print( "Start underscore mode",      "us" );
  70.   Print( "End underscore mode",          "ue" );
  71.   Print( "Start blinking mode",          "mb" );
  72.   Print( "Start bold mode",          "md" );
  73.   Print( "Start reverse mode",          "mr" );
  74.   Print( "Return to normal mode",      "me" );
  75.  
  76.   Print( "Scroll backwards",          "sr" );
  77.   Print( "Cursor motion",          "cm" );
  78.  
  79.   Print( "Up one line",              "up" );
  80.   Print( "Down one line",          "do" );
  81.   Print( "Left one space",          "le" );
  82.   Print( "Right one space",          "nd" );
  83.   Print( "Move to top left corner",      "ho" );
  84.  
  85.   Print( "Generated by \"UP\"",          "ku" );
  86.   Print( "Generated by \"DOWN\"",      "kd" );
  87.   Print( "Generated by \"LEFT\"",      "kl" );
  88.   Print( "Generated by \"RIGHT\"",      "kr" );
  89.   Print( "Generated by \"HOME\"",      "kh" );
  90.   Print( "Generated by \"END\"",      "k0" );
  91.   Print( "Generated by \"PGUP\"",      "k1" );
  92.   Print( "Generated by \"PGDN\"",      "k2" );
  93.   Print( "Generated by numeric \"+\"",      "k3" );
  94.   Print( "Generated by numeric \"-\"",      "k4" );
  95.   Print( "Generated by numeric \"5\"",      "k5" );
  96.  
  97.   exit( 0 );
  98.   }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. /****************************************************************/
  106. /*                                */
  107. /*        Print( comment, name )                    */
  108. /*                                */
  109. /*            If a termcap entry exists for "name", then    */
  110. /*        print out "comment" and the entry. Control    */
  111. /*        characters are printed as ^x.            */
  112. /*                                */
  113. /****************************************************************/
  114.  
  115.  
  116. Print( comment, name )
  117.   char *comment;
  118.   char *name;
  119.  
  120.   {
  121.   char  entry[ 50 ];
  122.   char *p = entry;
  123.  
  124.   if ( tgetstr( name, &p ) == NULL )
  125.     return;
  126.     
  127.   printf( "%-32s (%s) = ", comment, name );
  128.  
  129.   for ( p = entry;  *p != '\0';  ++p )
  130.     if ( *p < ' ' )
  131.       printf( "^%c", *p + '@' );
  132.     else if ( *p == '\177' )
  133.       printf( "^?" );
  134.     else
  135.       putchar( *p );
  136.  
  137.   putchar( '\n' );
  138.   }
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. /****************************************************************/
  146. /*                                */
  147. /*        Error( message, arg )                    */
  148. /*                                */
  149. /*            Printf the "message" and abort.            */
  150. /*                                */
  151. /****************************************************************/
  152.  
  153.  
  154. Error( message, arg )
  155.   char *message;
  156.   char *arg;
  157.  
  158.   {
  159.   fprintf( stderr, message, arg );
  160.   exit( 1 );
  161.   }
  162.